package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.bean.TanentBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TanentAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    private List<TanentBean> mTanentAdapter;
    private String TAG="AgentAdapter";
    public TanentAdapter(Context context, List<TanentBean> maxTanentAdapterDatas){
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mTanentAdapter = maxTanentAdapterDatas;
    }

    @Override
    public int getCount() {
        return mTanentAdapter.size();
    }

    @Override
    public Object getItem(int position) {
        return mTanentAdapter.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.level_item,parent,false);
            viewHolder = new ViewHolder();
            viewHolder.mLevel_name = convertView.findViewById(R.id.level_name);
            viewHolder.mLevel_number = convertView.findViewById(R.id.level_number);
            viewHolder.mLevel_time = convertView.findViewById(R.id.level_time);
            viewHolder.mLevel_details = convertView.findViewById(R.id.level_details);
            viewHolder.mLevel_uid = convertView.findViewById(R.id.level_uid);
            viewHolder.mLevel_UP=convertView.findViewById(R.id.level_tenant_chain);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        TanentBean tanentBean = mTanentAdapter.get(position);
        viewHolder.mLevel_name.setText(tanentBean.getAdmin_name());
        viewHolder.mLevel_number.setText(tanentBean.getUser_tel());

        String time=stampToDate(tanentBean.getReg_time());
        String yue=time.substring(5,7);
        String ri=time.substring(8,10);
        String t=time.substring(10,time.length()-3);

        viewHolder.mLevel_time.setText(yue+"月"+ri+"日"+t);
        viewHolder.mLevel_details.setText("详情");
        viewHolder.mLevel_uid.setText("");
        viewHolder.mLevel_UP.setText("");


        return convertView;
    }
    public static String stampToDate(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(Long.parseLong(s+"000"));
        res = simpleDateFormat.format(date);
        return res;
    }
    public static class ViewHolder{
        TextView mLevel_name;
        TextView mLevel_number;
        TextView mLevel_time;
        TextView mLevel_details;
        TextView mLevel_uid;
        TextView mLevel_UP;
    }

}
